﻿namespace _02.BankExersice.Accounts
{
    using System;
    using _02.BankExersice.Customers;

    public abstract class Account : IDepositable
    {
        private Customer customer;
        private decimal interestRate;

        protected Account(Customer customer)
            : this(customer, 0, 0)
        {
        }

        protected Account(Customer customer, decimal interestRate, decimal balance)
        {
            this.Customer = customer;
            this.InterestRate = interestRate;
            this.Balance = balance;
        }

        public decimal Balance { get; protected set; }

        public decimal InterestRate
        {
            get
            {
                return this.interestRate;
            }

            protected set
            {
                if (value < 0)
                {
                    throw new ArgumentNullException("Interest Rate must be positive number!");
                }

                this.interestRate = value;
            }
        }

        public Customer Customer
        {
            get
            {
                return this.customer;
            }

            protected set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Customer must not be null!");
                }

                this.customer = value;
            }
        }

        public virtual decimal CalculateInterestAmount(int numberOfMonths)
        {
            return numberOfMonths * this.InterestRate * this.Balance;
        }

        public virtual void Deposit(decimal amount)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException("Amount must be positive number!");
            }

            this.Balance += amount;
        }

        public override string ToString()
        {
            return string.Format("{0} Account: Customer: {1}, Balance: {2}", 
                this.GetType().Name, this.Customer, this.Balance);
        }
    }
}
